package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Student;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {
    Page<Student> page(String name, Integer degree, Integer clazzId);

    void deleteByIds(List<Integer> idList);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("INSERT INTO student (" +
            "name, no, gender, phone, degree, clazz_id, " +
            "id_card, is_college, address, graduation_date, " +
            "violation_count, violation_score, create_time, update_time" +
            ") VALUES (" +
            "#{name}, #{no}, #{gender}, #{phone}, #{degree}, #{clazzId}, " +
            "#{idCard}, #{isCollege}, #{address}, #{graduationDate}, " +
            "0, 0, NOW(), NOW()" + // 固定默认值：违规次数0，违规分数0
            ")")
    void insert(Student student);

    Student getById(Integer id);

    void updateById(Student student);

    void addViolation(Integer id, Integer score);

    @MapKey("name")
    List<Map> countStudentDegreeData();
}